home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / MDM_PROC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  24KB  |  648 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                    BinkleyTerm Modem Handler Module                      */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. int dial_modem (char *);
  51. void phone_translate (char *, char *);
  52. char *get_response (long);
  53. int parse_response (char *);
  54. void empty_delay (void);
  55.  
  56. #define FAILURE   0
  57. #define IGNORE    1
  58. #define CONNECTED 2
  59. #define RINGING   3
  60. #define INCOMING  4
  61.  
  62. struct resp_str
  63. {
  64.    char *resp;
  65.    unsigned disp;
  66. };
  67.  
  68. static struct resp_str mdm_resps[] = {
  69.                                       {"RINGING", 1},
  70.                                       {"RING RESPONSE", 1},
  71.                                       {"RING", 3},
  72.                                       {"CONNECT", 2},
  73.                                       {"RRING", 1},
  74.                                       {"BUSY", 0},
  75.                                       {"VOICE", 0},
  76.                                       {"ERROR", 0},
  77.                                       {"OK", 0},
  78.                                       {"NO CARRIER", 0},
  79. /* "NO DIAL TONE" or "NO DIALTONE" */ {"NO DIAL", 4},
  80.                                       {"DIALING", 1},
  81.                                       {"NO ANSWER", 0},
  82.                                       {"DIAL TONE", 1},
  83.                                       {NULL, 0}
  84. };
  85.  
  86. static char *response_string = "                                                  ";
  87.  
  88. void do_dial_strings ()
  89. {
  90.    MDM_TRNS *m;
  91.  
  92.    predial = normprefix;
  93.    postdial = normsuffix;
  94.  
  95.    m = mm_head;
  96.    while (m != NULL)
  97.       {
  98.       if (m->mdm & newnodedes.ModemType)
  99.          {
  100.          predial = m->pre;
  101.          postdial = m->suf;
  102.          return;
  103.          }
  104.       m = m->next;
  105.       }
  106. }
  107.  
  108. void try_2_connect (char *phnum)
  109. {
  110.    long t1;
  111.    int j, k;
  112.  
  113.    for (j = 0; (j < poll_tries && !KEYPRESS ()); j++) /* do polltries or till keypress */
  114.       {
  115.       CLEAR_INBOUND ();
  116.       k = dial_modem (phnum);
  117.  
  118.       if ((un_attended || doing_poll) && fullscreen)
  119.          {
  120.          ++hist.calls_made;
  121.          (void) sprintf (junk, "%-4d", hist.calls_made);
  122.          sb_move (history_hWnd, HIST_ATT_ROW, HIST_COL);
  123.          sb_puts (history_Out, junk);
  124.          }
  125.  
  126.       if ((k > 0) || KEYPRESS ())
  127.          break;
  128.       t1 = timerset (200);
  129.       mdm_hangup ();
  130.       while (!timeup (t1) && !KEYPRESS ())
  131.          time_release ();                        /* pause for 2 seconds */
  132.       }
  133.    if (KEYPRESS ())                              /* If user's been busy */
  134.       {
  135.       (void) FOSSIL_CHAR ();                     /* Eat the character   */
  136.       if (!CARRIER)                              /* Abort if no carrier */
  137.          {
  138.          status_line (MSG_TXT(M_CONNECT_ABORTED));
  139.          mdm_hangup ();
  140.          }
  141.       }
  142.  
  143.    predial = normprefix;
  144.    postdial = normsuffix;
  145. }
  146.  
  147. int try_1_connect (char *phnum)
  148. {
  149.    int k;
  150.  
  151.    if ((k = dial_modem (phnum)) <= 0)
  152.       {
  153.       if (k != -2)            /* NO DIAL TONE needs express service */
  154.          mdm_hangup ();
  155.       }
  156.  
  157.    if ((un_attended || doing_poll) && fullscreen)
  158.       {
  159.       ++hist.calls_made;
  160.       (void) sprintf (junk, "%-4d", hist.calls_made);
  161.       sb_move (history_hWnd, HIST_ATT_ROW, HIST_COL);
  162.       sb_puts (history_Out, junk);
  163.       }
  164.  
  165.    predial = normprefix;
  166.    postdial = normsuffix;
  167.  
  168.    return (k);
  169. }
  170.  
  171. void phone_translate (char *number, char *translated)
  172. {
  173.    PN_TRNS *p;
  174.  
  175.    (void) strcpy (translated, number);
  176.    for (p = pn_head; p != NULL; p = p->next)
  177.       {
  178.       if (strncmp (p->num, number, (unsigned int) (p->len)) == 0)
  179.          {
  180.          (void) sprintf (translated, "%s%s%s", p->pre, &(number[p->len]), p->suf);
  181.          break;
  182.          }
  183.       }
  184. }
  185.  
  186. int dial_modem (char *number)
  187. {
  188.    int resp;
  189.    long t;
  190.    char translated[50];
  191.  
  192.    janus_OK = 0;
  193.    ARQ_lock = 0;
  194.  
  195.    phone_translate (number, translated);
  196.    if (translated[0] == '\"')                    /* If it's a script          */
  197.       {
  198.       resp = do_script (translated);             /* then do it that way       */
  199.       if (fullscreen)                            /* & clean up the bottom line*/
  200.          bottom_line ();
  201.       return (resp);
  202.       }
  203.  
  204.    status_line (MSG_TXT(M_DIALING_NUMBER), translated);
  205.    if (un_attended && fullscreen)
  206.       {
  207.       do_ready (MSG_TXT(M_READY_DIALING));
  208.       }
  209.  
  210.    /* First of all, if we have something, don't hang up on the guy! */
  211.    if (!no_collide && CHAR_AVAIL ())
  212.       return (-1);
  213.  
  214.    if (dial_setup != NULL)
  215.       {
  216.       mdm_cmd_string (dial_setup, 1);
  217.       }
  218.    else
  219.       {
  220.       LOWER_DTR ();                              /* drop DTR to reset modem   */
  221.